package cn.stylefeng.guns.cloud.workflow.modular.controller;

import cn.stylefeng.guns.cloud.libs.scanner.annotation.PostResource;
import cn.stylefeng.guns.cloud.libs.scanner.stereotype.ApiResource;
import cn.stylefeng.guns.cloud.libs.web.base.BaseController;
import cn.stylefeng.guns.cloud.model.page.PageResult;
import cn.stylefeng.guns.cloud.model.web.response.ResponseData;
import cn.stylefeng.guns.cloud.workflow.modular.model.params.RunOrEndProcessParam;
import cn.stylefeng.guns.cloud.workflow.modular.model.params.TaskParam;
import cn.stylefeng.guns.cloud.workflow.modular.model.result.EndProcessResult;
import cn.stylefeng.guns.cloud.workflow.modular.model.result.RunProcessResult;
import cn.stylefeng.guns.cloud.workflow.modular.service.EndProcessService;
import cn.stylefeng.guns.cloud.workflow.modular.service.RunProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 流程监控控制器（运行中流程和历史流程）
 *
 * @Author xuyuxiang
 * @Date 2019/11/14 20:00
 **/
@RestController
@ApiResource(name = "流程监控管理接口", path = "/monitorProcess")
@Api(tags = "流程监控管理接口")
public class MonitorProcessController extends BaseController {

    @Autowired
    private RunProcessService runProcessService;

    @Autowired
    private EndProcessService endProcessService;

    /**
     * 获取运行中流程列表(分页)
     *
     * @Author xuyuxiang
     * @Date 2019/11/14 19:41
     **/
    @PostResource(name = "获取运行中流程列表(分页)", path = "/runList")
    @ApiOperation(value = "获取运行中流程列表(分页)", response = RunProcessResult.class)
    public ResponseData runList(@RequestBody RunOrEndProcessParam runProcessParam) {
        PageResult pageResult = runProcessService.list(runProcessParam);
        return ResponseData.success(pageResult);
    }

    /**
     * 获取已结束流程列表(分页)
     *
     * @Author xuyuxiang
     * @Date 2019/11/14 19:41
     **/
    @PostResource(name = "获取已结束流程列表(分页)", path = "/endList")
    @ApiOperation(value = "获取已结束流程列表(分页)", response = EndProcessResult.class)
    public ResponseData endList(@RequestBody RunOrEndProcessParam endProcessParam) {
        PageResult pageResult = endProcessService.list(endProcessParam);
        return ResponseData.success(pageResult);
    }

    /**
     * 挂起运行中流程
     *
     * @Author xuyuxiang
     * @Date 2019/11/14 19:52
     **/
    @PostResource(name = "挂起运行中流程", path = "/suspend")
    @ApiOperation(value = "挂起运行中流程")
    public ResponseData suspend(@RequestParam("processInstanceId") String processInstanceId) {
        runProcessService.suspend(processInstanceId);
        return ResponseData.success();
    }

    /**
     * 激活运行中流程
     *
     * @Author xuyuxiang
     * @Date 2019/11/14 19:53
     **/
    @PostResource(name = "激活运行中流程", path = "/active")
    @ApiOperation(value = "激活运行中流程")
    public ResponseData active(@RequestParam("processInstanceId") String processInstanceId) {
        runProcessService.active(processInstanceId);
        return ResponseData.success();
    }

    /**
     * 结束运行中流程（强制终止）
     *
     * @Author xuyuxiang
     * @Date 2019/11/14 19:53
     **/
    @PostResource(name = "结束运行中流程", path = "/end")
    @ApiOperation(value = "结束运行中流程")
    public ResponseData end(@RequestParam("processInstanceId") String processInstanceId) {
        runProcessService.end(processInstanceId);
        return ResponseData.success();
    }

    /**
     * 转办运行中流程
     *
     * @Author xuyuxiang
     * @Date 2019/11/14 19:53
     **/
    @PostResource(name = "转办运行中流程", path = "/changeAssignee")
    @ApiOperation(value = "转办运行中流程")
    public ResponseData changeAssignee(@RequestBody TaskParam taskParam) {
        runProcessService.changeAssignee(taskParam);
        return ResponseData.success();
    }


}


